package manning.chapterTwo;

import com.opensymphony.xwork2.ActionSupport;

public class HelloId extends ActionSupport{

	private static final String GREETING = "Hello ";

	public String execute(){
		
		/*if( getId() == null || getId().equals("") ){
			System.out.println("###getId(): '"+ getId() +"'");
			return "ERROR";
		}else{
			setCustomGreeting( GREETING + getId() );
			System.out.println("###getId(): '"+ getId() +"'");
			return "SUCCESS";
		}*/
		setCustomGreeting( GREETING + getId() );
			System.out.println("###getId(): '"+ getId() +"'");
			return "SUCCESS";
	}
	
	private String id;
	private String customGreeting;
	
	public String getId(){
		return id;
	}
	
	public void setId(String id){
		this.id = id;
	}
	
	public String getCustomGreeting()
    {
    	return customGreeting;
    }
    
    public void setCustomGreeting( String customGreeting ){
    	this.customGreeting = customGreeting;
    }
	
	public void validate(){
	
		if ( getId().length() == 0){
			addFieldError("id", "Id is required.");
		}
	
	}
}